package learn_concurrent._6;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class T5 {
	static final Logger logger = LoggerFactory.getLogger(T5.class);

	public static void main(String[] args) throws InterruptedException {

		Object a = new Object();
		Object b = new Object();

		new Thread(() -> {
			synchronized (a) {
				logger.info("lock a");
				try {
					Thread.sleep(500);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				synchronized (b) {
					logger.info("lock b");
					logger.info("work...");
				}
			}
		}, "t1").start();

		new Thread(() -> {
			synchronized (b) {
				logger.info("lock b");
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				synchronized (a) {
					logger.info("lock a");
					logger.info("work...");
				}
			}
		}, "t2").start();

	}

}
